home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJSRC111.ZIP / go32 / vcpi.asm < prev    next >
Assembly Source File  |  1993-11-21  |  5KB  |  329 lines

  1. ;This is file VCPI.ASM
  2. ;
  3. ;Copyright(C) Aug 5th 1991 Y.Shibata
  4. ;This file is distributed under the term of GNU GPL.
  5. ;
  6.     .386P
  7.  
  8.     include segdefs.inc
  9.     include vcpi.inc
  10.  
  11.     start_data16
  12. emm_name        db    "EMMXXXX0",0
  13. emm_namedisabled    db    "EMMQXXX0",0
  14. emm_namedisabled2    db    "$MMXXXX0",0
  15.     end_data16
  16.  
  17.     start_code16
  18. ;
  19. ;  EMM Installed Check
  20. ;
  21. ;word16    emm_present(void)
  22. ;
  23. ;result EMS Handle
  24. ;
  25.     public    _emm_present
  26. _emm_present    proc    near
  27.     ;
  28.     push    bp
  29.     mov    bp,sp
  30.     ;
  31.     mov    dx,offset emm_name
  32.     mov    ax,3d00H        ;Open Handle
  33.     int    DOS_REQ
  34.         mov     cl,1
  35.     jnc    short emm_ok
  36.     mov    dx,offset emm_namedisabled
  37.     mov    ax,3d00H        ;Open Handle
  38.     int    DOS_REQ
  39.     jnc    short emm_ok_d
  40.     mov    dx,offset emm_namedisabled2
  41.     mov    ax,3d00H        ;Open Handle
  42.     int    DOS_REQ
  43.     jc    short no_emm_driver
  44. emm_ok_d:
  45.     push    ax
  46.     mov    ax,3500h+EMS_REQ    ;Check for valid INT handler
  47.     int    DOS_REQ
  48.     mov    cx,es
  49.     or    cx,bx
  50.     pop    ax
  51.     je    short no_emm_driver
  52.         mov     cl,0
  53.  
  54. emm_ok:    mov    bx,ax
  55.     mov    ax,4400H        ;Get IOCTL Data
  56.     int    DOS_REQ
  57.     jc    short no_emm_driver
  58.     test    dx,80H            ;1 = Device , 0 = File
  59.     jz    short no_emm_driver
  60.     mov    ax,4407H        ;Get Output IOCTL Status
  61.     int    DOS_REQ
  62.     push    ax
  63.     mov    ah,3EH            ;Close Handle
  64.     int    DOS_REQ
  65.     pop    ax
  66.     cmp    al,-1            ;Ready?
  67.     jne    short no_emm_driver
  68.     ;
  69.         mov     ax,-1
  70.         cmp     cl,0
  71.         je      emm_present_end ; at least VCPI is
  72.     ;
  73.     mov    ah,40H            ;Get Status
  74.     int    EMS_REQ
  75.     cmp    ah,0
  76.     jne    short no_emm_driver
  77.     mov    ah,42H            ;Get Unallocate Page Count
  78.     int    EMS_REQ
  79.     cmp    ah,0
  80.     jne    short no_emm_driver
  81.     mov    ax,-1            ;Handle = -1(Invalid Handle No.)
  82.     cmp    bx,dx            ;Other Program EMS Page Used?
  83.     jne    short emm_present_end    ;Used!!
  84.     mov    bx,1
  85.     mov    ah,43H            ;Allocate Pages(1 Page Only)
  86.     int    EMS_REQ
  87.     cmp    ah,0
  88.     jne    short no_emm_driver
  89.     mov    ax,dx            ;Handle
  90.     jmp    short emm_present_end
  91.  
  92. no_emm_driver:
  93.     xor    ax,ax            ;Not Installed = 0
  94. emm_present_end:
  95.     pop    bp
  96.     ret
  97.     ;
  98. _emm_present    endp
  99.  
  100. ;
  101. ;  EMS Page Deallocated
  102. ;
  103. ;void ems_free(word16 ems_handle)
  104. ;
  105.     public    _ems_free
  106. _ems_free    proc    near
  107.     ;
  108.     push    bp
  109.     mov    bp,sp
  110.     ;
  111.     mov    dx,4[bp]        ;EMS_Handle
  112.     mov    ah,45H            ;Deallocate Pages
  113.     int    EMS_REQ
  114.     ;
  115.     pop    bp
  116.     ret
  117.     ;
  118. _ems_free    endp
  119.  
  120. ;
  121. ;  VCPI Installed Check
  122. ;
  123. ;word16    vcpi_present(void)
  124. ;
  125. ;result    -1:VCPI Installed 0:VCPI Not Installed
  126. ;
  127.     public    _vcpi_present
  128. _vcpi_present    proc    near
  129.     ;
  130.     push    bp
  131.     mov    bp,sp
  132.     ;
  133.     mov    ax,VCPI_PRESENT        ;VCPI Present
  134.     int    VCPI_REQ
  135.     sub    ah,1
  136.     sbb    ax,ax            ;ah = 0 -> AX = -1
  137.     ;
  138.     pop    bp
  139.     ret
  140.     ;
  141. _vcpi_present    endp
  142.  
  143. ;
  144. ;  VCPI Maximum page number
  145. ;
  146. ;word16    vcpi_maxpage(void)
  147. ;
  148. ;result    max returnable page number
  149. ;
  150.     public    _vcpi_maxpage
  151. _vcpi_maxpage    proc    near
  152.     push    bp
  153.     mov    bp,sp
  154.  
  155.     mov    ax,VCPI_MAX_PHYMEMADR
  156.     int    VCPI_REQ
  157.     shr    edx,12
  158.     mov    ax,dx
  159.  
  160.     pop    bp
  161.     ret
  162.  
  163. _vcpi_maxpage    endp
  164.  
  165. ;
  166. ;  VCPI Unallocated Page count
  167. ;
  168. ;word16    vcpi_capacity(void)
  169. ;
  170. ;result    Free VCPI Memory(Pages)
  171. ;
  172.     public    _vcpi_capacity
  173. _vcpi_capacity    proc    near
  174.     ;
  175.     push    bp
  176.     mov    bp,sp
  177.     ;
  178.     mov    ax,VCPI_MEM_CAPACITY
  179.     int    VCPI_REQ
  180.     mov    ax,dx            ;Cut Upper16Bit(CAUTION!!)
  181.     ;
  182.     pop    bp
  183.     ret
  184.     ;
  185. _vcpi_capacity    endp
  186.  
  187. ;
  188. ;  VCPI Memory Allocate
  189. ;
  190. ;word16    vcpi_alloc(void)
  191. ;
  192. ;result    Allocate Page No.
  193. ;
  194.     public    _vcpi_alloc
  195. _vcpi_alloc    proc    near
  196.     ;
  197.     push    bp
  198.     mov    bp,sp
  199.     ;
  200.     mov    ax,VCPI_ALLOC_PAGE
  201.     int    VCPI_REQ
  202.     test    ah,ah
  203.     je    vcpi_alloc_success
  204.     xor    ax,ax            ;Error result = 0
  205.     jmp    short vcpi_alloc_end
  206.     ;
  207. vcpi_alloc_success:
  208.     shr    edx,12
  209.     mov    ax,dx            ;Cut Upper16Bit (CAUTION!!)
  210. vcpi_alloc_end:
  211.     pop    bp
  212.     ret
  213.     ;
  214. _vcpi_alloc    endp
  215.  
  216. ;
  217. ;  VCPI Memory Deallocate
  218. ;
  219. ;void    vcpi_free(word16 page_number)
  220. ;
  221.     public    _vcpi_free
  222. _vcpi_free    proc    near
  223.     ;
  224.     push    bp
  225.     mov    bp,sp
  226.     ;
  227.     movzx    edx,word ptr 4[bp]
  228.     sal    edx,12            ;Address = Page_number * 4KB
  229.     mov    ax,VCPI_FREE_PAGE
  230.     int    VCPI_REQ
  231.     ;
  232.     pop    bp
  233.     ret
  234.     ;
  235. _vcpi_free    endp
  236.  
  237. ;
  238. ;  VCPI Get Interface
  239. ;
  240. ;word32    get_interface(word32 far *page_table,GDT_S *gdt)
  241. ;
  242.     public    _get_interface
  243. _get_interface    proc    near
  244.     ;
  245.     push    bp
  246.     mov    bp,sp
  247.     push    si
  248.     push    di
  249.     ;
  250.     push    es
  251.     mov    si,[bp+8]        ;DS:SI = &GDT[g_vcpicode]
  252.     les    di,[bp+4]        ;ES:DI = Page Table (DI = 0)
  253.     mov    ax,VCPI_INTERFACE
  254.     int    VCPI_REQ
  255.     mov    eax,ebx
  256.     shld    edx,eax,16        ;DX:AX = EBX
  257.     pop    es
  258.        ;
  259.     pop    di
  260.     pop    si
  261.     pop    bp
  262.     ret    
  263.     ;
  264. _get_interface    endp
  265.  
  266. ;
  267. ;  VCPI Get PIC Vector
  268. ;
  269. ;word16    vcpi_get_pic(void)
  270. ;
  271. ;Result MASTER PIC Vector No.(IRQ0)
  272. ;
  273.     public    _vcpi_get_pic
  274. _vcpi_get_pic    proc    near
  275.     ;
  276.     push    bp
  277.     mov    bp,sp
  278.     mov    ax,VCPI_GET_PIC_VECTOR
  279.     int    VCPI_REQ
  280.     mov    ax,bx            ;MASTER PIC Vector
  281.     pop    bp
  282.     ret
  283.     ;
  284. _vcpi_get_pic    endp
  285.  
  286. ;
  287. ;  VCPI Get PIC Vector
  288. ;
  289. ;word16    vcpi_get_secpic(void)
  290. ;
  291. ;Result SLAVE PIC Vector No.(IRQ0)
  292. ;
  293.     public    _vcpi_get_secpic
  294. _vcpi_get_secpic    proc    near
  295.     ;
  296.     push    bp
  297.     mov    bp,sp
  298.     mov    ax,VCPI_GET_PIC_VECTOR
  299.     int    VCPI_REQ
  300.     mov    ax,cx            ;SLAVE PIC Vector
  301.     pop    bp
  302.     ret
  303.     ;
  304. _vcpi_get_secpic    endp
  305.  
  306. ;
  307. ;  VCPI Set PIC Vector
  308. ;
  309. ;void    vcpi_set_pics(word16 master_pic, word16 slave_pic)
  310. ;
  311.     public    _vcpi_set_pics
  312. _vcpi_set_pics    proc    near
  313.     ;
  314.     push    bp
  315.     mov    bp,sp
  316.     mov    bx,4[bp]        ;MASTER PIC Vector
  317.     mov    cx,6[bp]        ;SLAVE PIC Vector
  318.     mov    ax,VCPI_SET_PIC_VECTOR
  319.     int    VCPI_REQ
  320.     pop    bp
  321.     ret
  322.     ;
  323. _vcpi_set_pics    endp
  324.  
  325.  
  326.     end_code16
  327.  
  328.     end
  329.